package cn.tedu.file;

import java.io.*;

/*本类用于练习字节输出流*/
public class TestOut {
    public static void main(String[] args) {
        //method1();
        method2();

    }

    private static void method2() {
        BufferedOutputStream out=null;
        try {
           out=new BufferedOutputStream(new FileOutputStream(new File("F:\\ready\\1.txt")));
            out=new BufferedOutputStream(new FileOutputStream("F:\\ready\\1.txt"));
            //out=new BufferedOutputStream(new FileOutputStream(new File("F:\\ready\\1.txt"),true));//追加
           // out=new BufferedOutputStream(new FileOutputStream("F:\\ready\\1.txt",true));//追加
            out.write(99);
            out.write(99);
            out.write(99);
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            try {
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    private static void method1() {
        //1,定义一个在本方法中都生效的局部变量
        FileOutputStream out=null;
        //2.创建字节输出流对象FOS-FileOutputStream

        try {
            //out=new FileOutputStream(new File("F:\\ready\\1.txt"));
           //out=new FileOutputStream("F:\\ready\\1.txt");
           out=new FileOutputStream(new File("F:\\ready\\1.txt"),true);
            out=new FileOutputStream("F:\\ready\\1.txt",true);
            out.write(97);
            out.write(97);
            out.write(97);
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            try {
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        }


    }
